<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% 
dim db, rs
set db=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")

filepath=server.MapPath("/afterhours/access/backend/admin.mdb")
sql="DispatchColors"
id= request.QueryString("id")
action=lcase(request.QueryString("action"))

db.open ("provider=microsoft.jet.oledb.4.0;data source=" & filepath)

rs.cursorlocation=3 'adUseClient
rs.cursortype= 2 'adOpenDynamic
rs.locktype= 3 'adLockOptimistic
rs.open sql,db


if action="edit" then
	sname=request.QueryString("sd")
	scolor=request.QueryString("sc")
	w=request.QueryString("w")
	
	rs.find "id=" & id
	if not rs.eof then
		rs("status_name")=sname
		rs("status_color")=scolor
		rs("where")=w
		rs.update
		%><SCRIPT TYPE="text/javascript">alert( "<%= rs("type") %>: '<%= sname %>' saved successfully.")</SCRIPT><%
	else
		%><SCRIPT TYPE="text/javascript">alert("<%= rs("type") %>: '<%= sname %>' not saved.\nCan't find ID:<%= id %>")</SCRIPT><%
	end if
end if

if action="delete" then
	rs.find "id=" & id
	if not rs.eof then
		status_name=rs("status_name")
		
		rs.delete
		
		%><SCRIPT TYPE="text/javascript">alert( "Status: '<%= status_name %>' deleted successfully.")</SCRIPT><%
	else
		%><SCRIPT TYPE="text/javascript">alert( "Status: '<%= status_name %>' not deleted.\nCan't find ID:<%= id %>")</SCRIPT><%
	end if
end if

if action="new" then
	rs.addnew
	rs("status_name")=request.QueryString("sd")
	rs("status_color")=request.QueryString("sc")
	rs("where")=request.QueryString("w")
	rs("type")="status"
	rs.update

	%><SCRIPT TYPE="text/javascript">alert("Status: '<%= request.QueryString("sd") %>' Added successfully.")</SCRIPT><%
end if

rs.activeconnection=nothing
rs.movefirst

'---------------------------- end ASP -----------------------------------
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML XMLNS="http://www.w3.org/1999/xhtml">

<HEAD>
<TITLE>Dispatch Status Colors</TITLE>
 
<SCRIPT TYPE="text/javascript">

function tr_mouseover(num,bgclr,brdrclr){
	trobj=document.getElementById("tr" + num)
	bobj=document.getElementById("b" + num)
	
	trobj.style.backgroundColor="#" + bgclr
	trobj.style.borderColor="#" + brdrclr
	bobj.style.visibility="visible"
}

function tr_mouseout(num,bgclr,brdrclr){
	trobj=document.getElementById("tr" + num)
	bobj=document.getElementById("b" + num)
	
	trobj.style.backgroundColor="#" + bgclr
	trobj.style.borderColor="#" + brdrclr
	bobj.style.visibility="hidden"
}

function save_click(id,num){
	s=document.getElementById("s" + num)
	w=document.getElementById("w" + num)
		
	sd=s.value
	
	if (sd == ""){
		alert("Can't Save.\nNo description given.");
		return;
	}
	
	sString=s.style.backgroundColor;
	if (sString.substring(0,3) == "rgb"){sString=rgbConvert(sString)}

	iLen=sString.length;
	sc=sString.substring(iLen,iLen-(iLen-1))  //right(s.style.backgroundColor,len(s.style.backgroundColor)-1)
	alert(sString + "    " + sc)
	w=w.value
		
	if (num == "new"){
		window.location.href="AdminStatusColors.asp?action=new&sd=" + sd + "&sc=" + sc + "&w=" + w
	}
	else{	
		var url="&id=" + id + "&sd=" + sd + "&sc=" + sc + "&w=" + w;

		window.location.href="AdminStatusColors.asp?action=edit" + url
	}
}

function rgbConvert(str) {
   str = str.replace(/rgb\(|\)/g, "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
   return ('#' + str.join(""));
}


function delete_click(id,desc){
	if (comfirm ("Are you sure you want to delete '" + desc + "'?\n Ok=Yes\nCancel=No")==flase){ return;}
	
	if (id ==""){
		alert("Can't Save.\nNo ID returned.")
		return;
	}

window.location.href="AdminStatusColors.asp?action=delete&id=" + id

}

function ColorPopUp(num){
	url="ColorPicker.asp"
	params="dialogwidth: 580px; dialogHeight: 360px; edge: raised; center: yes; status:no; scroll: no"
	
	var cppop=window.showModalDialog(url,num,params)
	if (cppop.substring(0,1) =="#"){
		document.getElementById("s" + num).style.backgroundColor=cppop
	}
	
	//cppop=window.open (url,"ColorPicker",params)'
}
</SCRIPT>

<LINK HREF="UniversalStyleSheet.css" REL="stylesheet" TYPE="text/css" />
</HEAD>

<BODY>
<DIV STYLE="position:absolute" ID="ColorPickerDiv"> </DIV>
<FORM ID="colorform" NAME="colorform" METHOD="post">
<TABLE border=1 WIDTH="400" STYLE="border-width:thin; border-color:#009900; background-color:#CCFFCC; border-style:outset" CELLSPACING="5">


<%
st=0
do until rs.eof
st=st+1

if lcase(rs("type"))="function" then
	disabled="disabled='disabled'"
else
	disabled=""
end if
%>
<TR ID="tr<%= st %>" STYLE="background-color:#ffffff; border-color:#dddddd;" onMouseOver="tr_mouseover(<%= st %>,'99CCFF','006600') " onMouseOut="tr_mouseout(<%= st %>,'ffffff','ffffff')" VALIGN="middle">

<TD STYLE="border-top:none; border-left:none; border-right:none; border-bottom:#000000; border-width:2px; border-style:outset; border-color:#CCCCCC">

<!--toolbar-->

<SPAN ID="b<%= st %>" STYLE="visibility:hidden; display:block; background:#009999; border-width:thin; border-style:ridge; border-color:#003366">

<IMG SRC="Images/paint_bucket.gif" BORDER="0" TITLE="Choose Color" STYLE="vertical-align:bottom; cursor:pointer;" onMouseOver="this.style.background='#CCFFCC'" onMouseOut="this.style.background='none'" onClick="ColorPopUp ('<%= st %>') ">

|
<IMG SRC="Images/save_icon.gif" BORDER="0" TITLE="Save" STYLE="cursor:pointer; vertical-align:bottom" onMouseOver="this.style.background='#CCFFCC'" onMouseOut="this.style.background='none'" onClick="save_click('<%= rs("id") %>','<%= st %>')"> 
|
<% if rs("type")<>"function" then %>
<IMG SRC="Images/delete.gif" BORDER="0" TITLE="Delete" STYLE="cursor:pointer; vertical-align:bottom" onMouseOver="this.style.background='#CCFFCC'" onMouseOut="this.style.background='none'" onClick="delete_click ('<%= rs("id") %>','<%= rs("status_name") %>')">
<% end if %>
</SPAN>


<!--end toolbar -->

<TABLE BORDER="0">
<TR>
<TD>
<P STYLE="font-family:Arial, Helvetica, sans-serif; font-size:9px; display:table-">Who Has Permission: </P>
<% if rs("type")="function" then disabled="disabled=disabled" %>
<SELECT NAME="w<%= st %>" ID="w<%= st %>" STYLE="border-width:1px; border-style:solid; border-color:#000000; margin-bottom:5px; width:150px; display:table-cell" <%= disabled %> > 
	<OPTION VALUE="dispatch">Dispatch</OPTION>
	<OPTION VALUE="operator">Operator</OPTION>
	<OPTION VALUE="both">Both</OPTION>
</SELECT>

<SCRIPT TYPE="text/javascript">
wval="<%= rs("where") %>"
switch (wval)
	{
	case "dispatch":
		i=0;
		break;
	case "operator":
		i=1;
		break;
	case "both":
		i=2;
		break;
}

document.getElementById("w<%= st %>").selectedIndex=i
</SCRIPT>
</TD>

<TD>
<P STYLE="font-family:Arial, Helvetica, sans-serif; font-size:9px; display:table-">Description:</P>
<INPUT NAME="s<%= st %>" TYPE="text" ID="s<%= st %>" STYLE="background-color:#<%= rs("status_color") %>; border-width:1px; border-style:solid; border-color:#000000; margin-bottom:5px; text-align:center; width:150px" VALUE="<%= rs("status_name") %>" SIZE="30" MAXLENGTH="50" <%= disabled %>>

<SPAN STYLE="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#999999">
<%= rs("type") %>
</SPAN>
</TD>
</TR>
</TABLE>



</TD>
</TR>

<%
rs.movenext
loop
%>
<TR>
<TD STYLE="background:#000000; width:5px; font-size:1px">&nbsp;
</TD>
</TR>

<TR ID="trnew" STYLE="background-color:#dddddd; border-style:solid; border-color:#FFFFFF" onMouseOver="tr_mouseover('new','cccccc','ff0000') " onMouseOut="tr_mouseout('new','dddddd','ffffff') ">

<TD>
<SPAN STYLE="font-size:10px; font-weight:bold; text-decoration:underline; font-family:Arial, Helvetica, sans-serif;">Add New Status:<BR></SPAN>
<SPAN ID="bnew" STYLE="visibility:hidden; display:block; background:#999999; border-width:thin; border-style:ridge; border-color:#660000">

<IMG SRC="Images/paint_bucket.gif" BORDER="0" TITLE="Choose Color" STYLE="vertical-align:bottom; cursor:pointer;" onMouseOver="this.style.background='#CCFFCC'" onMouseOut="this.style.background='none'" onClick="ColorPopUp('new') ">

|
<IMG SRC="Images/save_icon.gif" BORDER="0" TITLE="Save" STYLE="cursor:pointer; vertical-align:bottom" onMouseOver="this.style.background='#CCFFCC'" onMouseOut="this.style.background='none'" onClick="save_click('new','new') "> 

</SPAN>

<TABLE BORDER="0">
<TR>
<TD>
<P STYLE="font-family:Arial, Helvetica, sans-serif; font-size:9px; display:table-">Who Has Permission: </P>
<SELECT NAME="wnew" ID="wnew" STYLE="border-width:1px; border-style:solid; border-color:#000000; margin-bottom:5px; width:150px; display:table-cell"> 
	<OPTION VALUE="dispatch">Dispatch</OPTION>
	<OPTION VALUE="operator">Operator</OPTION>
	<OPTION VALUE="both" SELECTED="SELECTED">Both</OPTION>
</SELECT>

</TD>

<TD>
<P STYLE="font-family:Arial, Helvetica, sans-serif; font-size:9px; display:table-">Description:</P>
<INPUT NAME="snew" TYPE="text" ID="snew" STYLE="border-width:1px; border-style:solid; border-color:#000000; margin-bottom:5px; text-align:center; width:150px; background-color:#FFFFFF" SIZE="30" MAXLENGTH="50">

</TD>
</TR>
</TABLE>


<%
rs.close
db.close
set rs=nothing
set db=nothing
%>
</TD>
</TR>

</TABLE>
</FORM>

</BODY>
</HTML>
